function d() {
  return g().__VUE_DEVTOOLS_GLOBAL_HOOK__;
}
function g() {
  return typeof navigator < "u" && typeof window < "u" ? window : typeof global < "u" ? global : {};
}
const _ = typeof Proxy == "function", h = "devtools-plugin:setup", O = "plugin:settings:set";
let u, f;
function S() {
  var o;
  return u !== void 0 || (typeof window < "u" && window.performance ? (u = !0, f = window.performance) : typeof global < "u" && ((o = global.perf_hooks) === null || o === void 0 ? void 0 : o.performance) ? (u = !0, f = global.perf_hooks.performance) : u = !1), u;
}
function w() {
  return S() ? f.now() : Date.now();
}
class y {
  constructor(s, n) {
    this.target = null, this.targetQueue = [], this.onQueue = [], this.plugin = s, this.hook = n;
    const i = {};
    if (s.settings)
      for (const e in s.settings) {
        const t = s.settings[e];
        i[e] = t.defaultValue;
      }
    const r = `__vue-devtools-plugin-settings__${s.id}`;
    let a = Object.assign({}, i);
    try {
      const e = localStorage.getItem(r), t = JSON.parse(e);
      Object.assign(a, t);
    } catch {
    }
    this.fallbacks = {
      getSettings() {
        return a;
      },
      setSettings(e) {
        try {
          localStorage.setItem(r, JSON.stringify(e));
        } catch {
        }
        a = e;
      },
      now() {
        return w();
      }
    }, n && n.on(O, (e, t) => {
      e === this.plugin.id && this.fallbacks.setSettings(t);
    }), this.proxiedOn = new Proxy({}, {
      get: (e, t) => this.target ? this.target.on[t] : (...l) => {
        this.onQueue.push({
          method: t,
          args: l
        });
      }
    }), this.proxiedTarget = new Proxy({}, {
      get: (e, t) => this.target ? this.target[t] : t === "on" ? this.proxiedOn : Object.keys(this.fallbacks).includes(t) ? (...l) => (this.targetQueue.push({
        method: t,
        args: l,
        resolve: () => {
        }
      }), this.fallbacks[t](...l)) : (...l) => new Promise((c) => {
        this.targetQueue.push({
          method: t,
          args: l,
          resolve: c
        });
      })
    });
  }
  async setRealTarget(s) {
    this.target = s;
    for (const n of this.onQueue)
      this.target.on[n.method](...n.args);
    for (const n of this.targetQueue)
      n.resolve(await this.target[n.method](...n.args));
  }
}
function p(o, s) {
  const n = o, i = g(), r = d(), a = _ && n.enableEarlyProxy;
  if (r && (i.__VUE_DEVTOOLS_PLUGIN_API_AVAILABLE__ || !a))
    r.emit(h, o, s);
  else {
    const e = a ? new y(n, r) : null;
    (i.__VUE_DEVTOOLS_PLUGINS__ = i.__VUE_DEVTOOLS_PLUGINS__ || []).push({
      pluginDescriptor: n,
      setupFn: s,
      proxy: e
    }), e && s(e.proxiedTarget);
  }
}
export {
  S as isPerformanceSupported,
  w as now,
  p as setupDevtoolsPlugin
};
